package com.ruoyi.web.controller.smartHighway;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.smartHighway.domain.Guest;
import com.ruoyi.smartHighway.service.IGuestService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户 Controller
 * 
 * @author ljj
 * @date 2024-08-05
 */
@RestController
@RequestMapping("/smartHighway/guest")
public class GuestController extends BaseController {

    @Autowired
    private IGuestService guestService;

    /**
     * 查询客户 列表
     */
    @PreAuthorize("@ss.hasPermi('smartHighway:guest:list')")
    @GetMapping("/list")
    public TableDataInfo list(Guest guest) {
        startPage();
        List<Guest> list = guestService.selectGuestList(guest);
        return getDataTable(list);
    }

    /**
     * 导出客户 列表
     */
    @PreAuthorize("@ss.hasPermi('smartHighway:guest:export')")
    @Log(title = "客户 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Guest guest) {
        List<Guest> list = guestService.selectGuestList(guest);
        ExcelUtil<Guest> util = new ExcelUtil<Guest>(Guest.class);
        util.exportExcel(response, list, "客户 数据");
    }

    /**
     * 获取客户 详细信息
     */
    @PreAuthorize("@ss.hasPermi('smartHighway:guest:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(guestService.selectGuestById(id));
    }

    /**
     * 新增客户 
     */
    @PreAuthorize("@ss.hasPermi('smartHighway:guest:add')")
    @Log(title = "客户 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Guest guest) {
        return toAjax(guestService.insertGuest(guest));
    }

    /**
     * 修改客户 
     */
    @PreAuthorize("@ss.hasPermi('smartHighway:guest:edit')")
    @Log(title = "客户 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Guest guest) {
        return toAjax(guestService.updateGuest(guest));
    }

    /**
     * 删除客户 
     */
    @PreAuthorize("@ss.hasPermi('smartHighway:guest:remove')")
    @Log(title = "客户 ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(guestService.deleteGuestByIds(ids));
    }
}
